<?php

namespace backend\modules\home\models;

use Yii;

/**
 * This is the model class for table "net_consult".
 *
 * @property int $id
 * @property string $usename
 * @property string $phone
 * @property string $question
 * @property int $status
 * @property string $remark
 * @property int $create_at
 * @property int $update_at
 */
class Consult extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'net_consult';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['usename', 'phone', 'question'], 'required'],
            [['status', 'create_at', 'update_at'], 'integer'],
            [['usename'], 'string', 'max' => 30],
            [['question', 'remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'usename' => '称呼',
            'phone' => '联系电话',
            'question' => '咨询内容',
            'status' => '状态',
            'remark' => '备注',
            'create_at' => '创建时间',
            'update_at' => '更新时间',
        ];
    }

    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){
            if($this->isNewRecord){
                $this->create_at = time();
                $this->update_at = time();
                $this->status = 0;
                $this->remark = '';
            }else{
                $this->update_at = time();
            }
            return true;
        }
        return false;
    }
}
